export default class FrameAnimation {

    info:any;//修改信息

    timer:any;//渲染器

    runTime:number;//运行速率

    runIndex:number = 0;//当前播放帧

    runLength:number = 0;//当前播放帧

    constructor(infoAni:any){
        this.info = infoAni;
        this.info.value.aniImg = this.info.value.aniArr[0]
        // console.log("ani",this.info);
        let aniTime = this.info.value.aniTime
        let aniArr = this.info.value.aniArr
        this.runLength = aniArr.length
        this.runTime = parseFloat(aniTime) / aniArr.length
        this.start()
    }

    start(){
        clearInterval(this.timer)
        this.timer = setInterval(()=>{
            this.info.value.aniImg = this.info.value.aniArr[this.runIndex]
            this.runIndex++
            if(this.runIndex > this.runLength-1){
                this.runIndex = 0
            }
        },this.runTime)
    }

    restart(){
        this.runIndex = 0
        this.start()
    }

    dispose(){
        clearInterval(this.timer)
    }

}